#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "surveillance.h"
#include "medecin.h"
#include "service_info.h"
#include "hygiene.h"
#include "maintenance.h"
#define MAX 50
int rech_su_i(char fsurv[], long int ide);
int rech_su_m(char fsurv[],char modp[]);
int rech_me_i(char fmed[], long int ide);
int rech_me_m(char fmed[],char modp[]);
int rech_in_i(char finfo[], long int ide);
int rech_in_m(char finfo[],char modp[]);
int rech_ma_i(char fmaint[], long int ide);
int rech_ma_m(char fmaint[],char modp[]);
int rech_hy_i(char fhyg[], long int ide);
int rech_hy_m(char fhyg[],char modp[]);
void time();

/***************************************************************************/

main()
{ 
long int ide;
int t,tmp,test=0;
int a,c;
char modp[MAX];
 system("clear");
do
{
do 
{ 
	printf("\t\t\t\ndonner votre id : ");
	scanf("%ld",&ide);
	printf("\t\t\t\ndonner un mot de passe : ");
	scanf("%s",modp);
	c=(ide/10000);
	switch (c)
	{
	//service info	  
				  case 2 :
		  		  t=rech_in_i("finfo",ide);
				  a=rech_in_m("finfo",modp);
					if (t==1 && a==1)
					{ test=6; printf("\t\t\t\n      ahla wa sahla bil m3alem \n\n"); }
					else { test=test+1; printf("\t\t\t\n     WARNING - donnees incorrectes - \n\n" ); }
				 break;
				
	//surveillance	  
				  case 3 :
		  	          t=rech_su_i("fsurv",ide);
				  a=rech_su_m("fsurv",modp);
					if (t==1 && a==1)
					{ test=6; printf("\t\t\t\n      ahla wa sahla bil m3alem \n\n"); }
					else { test=test+1; printf("\t\t\t\n     WARNING - donnees incorrectes - \n\n" ); }
				 break;
				
	//medecins	  	  
				  case 7 :
		  		  t=rech_me_i("fmed",ide);
				  a=rech_me_m("fmed",modp);
					if (t==1 && a==1)
					{ test=6; printf("\t\t\t\n      ahla wa sahla bil m3alem \n\n"); }
					else { test=test+1; printf("\t\t\t\n     WARNING - donnees incorrectes - \n\n" ); }
				 break;
	}
}while (test<3);
	if (test==3)
	{ tmp=1; time(); }
}while (tmp==1 && test!=6);
}
/************************************************************************/

int rech_su_i(char fsurv[],long int ide)
{
FILE *f;
int t=0;
surveillance p;
f=fopen(fsurv,"rb");
if (f!=NULL)
 {	while(!feof(f)&&t==0)
   { 
	fread(&p,sizeof(surveillance),1,f);
       if(p.id==ide)
           t=1;	
   }
 }
else t=-1;
return(t);
fclose(f);
}
int rech_su_m(char fsurv[],char modp[])
{
 FILE *f;
int a=0;
surveillance p;
f=fopen(fsurv,"rb");
if (f!=NULL)
 {	while(!feof(f)&&a==0)
   {
	fread(&p,sizeof(surveillance),1,f);
        if(strcmp(p.mdp,modp)==0)
           a=1;
   }
 }
else a=-1;
return(a);
fclose(f);
}

/************************************************************************/
 int rech_me_i(char fmed[],long int ide)
{
FILE *f;
int t=0;
medecin p;
f=fopen(fmed,"rb");
if (f!=NULL)
{	while(!feof(f)&&t==0)
   {
     fread(&p,sizeof(medecin),1,f);
       if(p.id==ide)
           t=1;
   }
}
else t=-1;
return(t);
fclose(f);
}
int rech_me_m(char fmed[],char modp[])
{
 FILE *f;
int a=0;
medecin p;
f=fopen(fmed,"rb");
if (f!=NULL)
{	while(!feof(f) && a==0)
   {
     fread(&p,sizeof(medecin),1,f);
       if(strcmp(p.mdp,modp)==0)
           a=1;
   }
}
else a=-1;
return(a);
fclose(f);
}
/************************************************************************/
int rech_in_i(char finfo[],long int ide)
{
FILE *f;
int t=0;
service_info p;
f=fopen(finfo,"rb");
if (f!=NULL)
{	while(!feof(f) && t==0)
   {
     fread(&p,sizeof(service_info),1,f);
       if(p.id==ide)
           t=1;
   }
}
else t=-1;
return(t);
fclose(f);
}
int rech_in_m(char finfo[],char modp[])
{
 FILE *f;
int a=0;
service_info p;
f=fopen(finfo,"rb");
if (f!=NULL)
{	while(!feof(f) && a==0)
   {
     fread(&p,sizeof(service_info),1,f);
       if(strcmp(p.mdp,modp)==0)
           a=1;
   }
}
else a=-1;
return(a);
fclose(f);
}
/************************************************************************/
void time()
{
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:30\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:29\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:28\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:27\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:26\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:25\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:24\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:23\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:22\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:21\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:20\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:19\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:18\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:17\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:16\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:15\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:14\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:13\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:12\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:11\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:10\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:09\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:08\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:07\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:06\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:05\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:04\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:03\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:02\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:01\n\n");
 system("sleep 1");
 system("clear");
 printf("\n\n\n\t\t\t\t\t\t waiting 00:00\n\n\n");
 system("sleep 1");
 system("clear");
}




















